use std::fmt::{Debug, Formatter};
use yew::{Callback, UseReducerHandle};
use crate::business::websocket::receive_send_handle::ImReceiveSendHandle;
use crate::business::websocket::websocket_view::ImWebSocketStatus;

#[derive(Clone)]
pub struct AppState {
    pub total: u32,
    pub login_user_id: Option<String>,
    pub receive_send_handle: Option<UseReducerHandle<ImReceiveSendHandle>>,
    pub websocket_status: ImWebSocketStatus, // websocket状态
    pub set_login_user_id_callback: Option<Callback<String>>,
    pub set_data_callback: Option<Callback<(String, String)>>,
}

impl PartialEq for AppState {
    fn eq(&self, other: &Self) -> bool {
        self.total == other.total
    }
}

impl Debug for AppState {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "websocket, total: {}", self.total)
    }
}

impl AppState {
    pub fn new() -> Self {
        Self {
            total: 0,
            login_user_id: None,
            receive_send_handle: None,
            websocket_status: ImWebSocketStatus::Disconnected,
            set_login_user_id_callback: None,
            set_data_callback: None,
        }
    }
}
